<template>
    <div>
      <!-- 面包屑导航区 -->
         <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片区 -->
        <el-card>
              <el-row :gutter="10">
                <el-col :span="6">
                     <el-input 
                     placeholder="请输入内容" 
                      clearable
                      v-model="paramsInfo.query"
                     >
                        <el-button slot="append" icon="el-icon-search" @click="getOrdersList" ></el-button>
                    </el-input>
                </el-col>
              </el-row>

              <!-- 表格区域 -->
         <el-table :data="ordersList"  border stripe>
            <el-table-column type="index" width="80"></el-table-column>
            <el-table-column prop="order_number" label="订单编号"></el-table-column>
            <el-table-column label="订单价格(元)" >
                <template slot-scope="{row}">
                    {{row.order_price}}元
                </template>
            </el-table-column>
            <el-table-column label="是否付款">
                  <template slot-scope="{row}">
                    <el-tag type="warning" v-if="row.order_pay == '0' ">未付款</el-tag>
                    <el-tag type="success" v-else>已付款</el-tag>
                  </template>
            </el-table-column>
            <el-table-column prop="is_send" label="是否发货"></el-table-column>
            <el-table-column prop="create_time" label="下单时间"></el-table-column>
            <el-table-column label="操作" width="180">
                 <template>
                    <el-button type="primary" size="mini" icon="el-icon-edit" @click="editAddress">编辑</el-button>
                    <el-button type="success" size="mini" icon="el-icon-delete-location">查看</el-button>
                </template>
            </el-table-column>
         </el-table>
           <!-- 分页 -->
                 <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="paramsInfo.pagenum"
                    :page-sizes="[1, 3, 5, 10]"
                    :page-size="paramsInfo.pagesize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                 </el-pagination>
            </el-card>
            <!-- 编辑弹框 -->
            <el-dialog title="修改地址" :visible.sync="dialogVisible" width="40%" @close="closeDialog">

                <el-form :model="editForm" :rules="editRules" ref="editFormRef" label-width="100px" class="demo-ruleForm">
                <el-form-item label="省市区/县" prop="address1">
                    <el-cascader
                        v-model="editForm.address1"
                        :options="citydata"
                        :props="editProps">
                    </el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address2">
                  <el-input v-model="editForm.address2"></el-input>
                </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer">
                  <el-button @click="dialogVisible = false">取 消</el-button>
                  <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
                </span>
              </el-dialog>
    </div>
</template>

<script>
import citydata from '@/assets/citydata'
export default {
  name:'ordersIndex',
  components: {},
  props: {},
  data() {
    return {
        // 订单列表数据
        ordersList:[],
        paramsInfo:{
            query:'',
            pagenum:1,
            pagesize:10
        },
        total:0,
        dialogVisible:false,
        editForm:{
            address1:[],
            address2:''
        },
        editRules:{
          address1:[{ required: true, message: '请选择区县', trigger: 'blur' }],
          address2:[{ required: true, message: '请填写详细地址', trigger: 'blur' }]
        },
        // 级联选择器配置
        citydata:citydata,
        editProps:{
           expandTrigger: 'hover',
           value:'value',
           label:'label',
           children:'children'
        }
    }
  },
  created() {
    this.getOrdersList()
  },
  methods: {
   async getOrdersList(){
       const {data:res} = await this.$http.get('/orders',{
        params:this.paramsInfo
       })
       if(res.meta.status !== 200) return this.$message.error('获取订单列表数据失败')
       this.ordersList = res.data.goods
       this.total = res.data.total
    },
    handleSizeChange(newValue){
       this.paramsInfo.pagesize = newValue
       this.getOrdersList()
    },
    handleCurrentChange(newValue){
        this.paramsInfo.pagenum = newValue
        this.getOrdersList()
    },
    editAddress(){
       this.dialogVisible = true
    },
    closeDialog(){
      this.$refs.editFormRef.resetFields()
    }
  }
};
</script>
<style scoped lang='less'>
.el-breadcrumb{
    margin-bottom: 15px;
   }
   .el-table{
    margin-top: 15px;
    margin-bottom: 15px;
   }
</style>